package GUI;

import Utils.MSJ_JOptionPane;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 * <b>Use this class to check that the mandatory fields are not empty.</b>
 *
 * @author Mohamed Tarek Salama
 * @version 1.0 BETA
 */
public class MSJ_Mandatory {

    /**
     * Check if the <b>JTextField</b> is a mandatory field <br> if it mandatory
     * and still empty it will show <b>JOptionPane</b> error. Then hide the (*)
     * label.
     *
     * @param text : Text of the text field.
     * @param label : JLabel : label of the (*).
     */
    public void mandatoryTextField(JTextField text, JLabel label) {
        if (!text.getText().equals("")) {
            label.setVisible(false);
        } else {
            label.setVisible(true);
            MSJ_JOptionPane.show_Warning_Message("Please, Fill the mandatory fields");
        }
    }

    /**
     * Check if the <b>JTextField</b> is a mandatory field <br> if it mandatory
     * and still empty it will return <b>False</b>. Then hide the (*) label.
     *
     * @param text : Text of the text field.
     * @param label : JLabel : label of the (*).
     * @return boolean
     */
    public boolean mandatory_TextField(JTextField text, JLabel label) {
        if (!text.getText().equals("")) {
            label.setVisible(false);
            return true;
        } else {
            label.setVisible(true);
            return false;
        }
    }

    /**
     * Check if the <b>JPasswordField</b> is a mandatory field <br> if it
     * mandatory and still empty it will show <b>JOptionPane</b> error. Then
     * hide the (*) label.
     *
     * @param text : Text of the password field.
     * @param label : JLabel : label of the (*).
     */
    public void mandatoryPassField(JPasswordField text, JLabel label) {
        if (!text.getText().equals("")) {
            label.setVisible(false);
        } else {
            label.setVisible(true);
            MSJ_JOptionPane.show_Warning_Message("Please, Fill the mandatory fields");
        }
    }

    /**
     * Check if the <b>JPasswordField</b> is a mandatory field <br> if it
     * mandatory and still empty it will return <b>False</b>. Then hide the (*)
     * label.
     *
     * @param text : Text of the password field.
     * @param label : JLabel : label of the (*).
     * @return boolean
     */
    public boolean mandatory_PassField(JPasswordField text, JLabel label) {
        if (!text.getText().equals("")) {
            label.setVisible(false);
            return true;
        } else {
            label.setVisible(true);
            return false;
        }
    }

    /**
     * /**
     * Check if the <b>JTextArea</b> is a mandatory field <br> if it mandatory
     * and still empty it will show <b>JOptionPane</b> error. Then hide the (*)
     * label.
     *
     * @param text : Text of the text aria.
     * @param label : JLabel : label of the (*).
     */
    public void mandatoryTextAria(JTextArea text, JLabel label) {
        if (!text.getText().equals("")) {
            label.setVisible(false);
        } else {
            label.setVisible(true);
            MSJ_JOptionPane.show_Error_Message("Please, Fill the mandatory fields");
        }
    }

    /**
     * /**
     * Check if the <b>JTextArea</b> is a mandatory field <br> if it mandatory
     * and still empty it will return <b>False</b>. Then hide the (*) label.
     *
     * @param text : Text of the text aria.
     * @param label : JLabel : label of the (*).
     * @return boolean
     */
    public boolean mandatory_TextAria(JTextArea text, JLabel label) {
        if (!text.getText().equals("")) {
            label.setVisible(false);
            return true;
        } else {
            label.setVisible(true);
            return false;
        }
    }
}